package com.mlz.mlzmall.ui.utils.mlz;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mlz.mlzmall.R;
import com.mlz.mlzmall.ui.utils.util.ScreenUtils;


public class DialogView extends Dialog implements View.OnClickListener {
	private int item=2;
	private Context context;
	private LayoutInflater inflater;
	private int position;
	private TextView confirm, cancel,clean_one;
	private OnBtnClickListener oncl;
	private int view;
	private String intent,body;
	String[] vale;
	int[] layout;
	LinearLayout ll;

	public DialogView(Context context, int view, int theme) {
		super(context, theme);
		this.context = context;
		this.view = view;
		inflater = LayoutInflater.from(context);
	}

	public DialogView(Context context, int view, int theme, int item) {
		super(context, theme);
		this.context = context;
		this.view = view;
		this.item = item;
		inflater = LayoutInflater.from(context);
	}
	public DialogView(Context context, int view, int theme, int item, String body) {
		super(context, theme);
		this.context = context;
		this.view = view;
		this.item = item;
		this.body = body;
		inflater = LayoutInflater.from(context);
	}
	public DialogView(Context context, int view, int theme, int item, int[] g, String[] ss) {
		super(context, theme);
		this.context = context;
		this.view = view;
		this.item = item;
		vale = ss;
		layout = g;
		inflater = LayoutInflater.from(context);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ll = (LinearLayout) inflater.inflate(view, null);
		ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ScreenUtils.getScreenWidth(context)*45/60, ViewGroup.LayoutParams.WRAP_CONTENT);

		setContentView(ll, params);
		confirm = (TextView) findViewById(R.id.confirm);
		confirm.setOnClickListener(this);
		if(item == 1){
			TextView tv_body = (TextView) findViewById(R.id.context);
			tv_body.setText(body);
		}
		else if(item == 2) {
			TextView tv_body = (TextView) findViewById(R.id.context);
			tv_body.setText(body);
			cancel = (TextView) findViewById(R.id.cancel);
			cancel.setOnClickListener(this);
		}else if(item == 3){
			TextView tv_body = (TextView) findViewById(R.id.context);
			tv_body.setText(body);
			cancel = (TextView) findViewById(R.id.cancel);
			cancel.setOnClickListener(this);
			clean_one = (TextView) findViewById(R.id.clean_one);
			clean_one.setOnClickListener(this);

		}
		if(item == 4) {
			cancel = (TextView) findViewById(R.id.cancel);
			cancel.setOnClickListener(this);
			setViewContent(layout, vale);
		}

	}
	void setViewContent(int[] AA,String[] WW){
		for(int i = 0;i<AA.length;i++){
			TextView textView = (TextView) ll.findViewById(AA[i]);
			textView.setText(WW[i]);
		}
	}

	public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
		this.oncl = onBtnClickListener;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public int getPosition() {
		return position;
	}
	public void setContent(String one_str) {
		confirm.setText(one_str);
	}

	public void setContent(String one_str,String tow_str) {
		confirm.setText(one_str);
		cancel.setText(tow_str);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.confirm :
				if (oncl != null) {
					oncl.onclick(0);
				}
				this.dismiss();
				break;
			case R.id.cancel :
				if (oncl != null) {
					oncl.onclick(1);
				}
				this.dismiss();
				break;
			case R.id.clean_one :
				if (oncl != null) {
					oncl.onclick(2);
				}
				this.dismiss();
				break;
			default :
				break;
		}
	}
	public interface OnBtnClickListener {
		void onclick(int i);
	}

}
